import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/utils/utils.dart';
import 'package:url_launcher/url_launcher.dart';

class FocusTencentDiaog extends StatefulWidget {
  @override
  _FocusTencentDiaogState createState() => _FocusTencentDiaogState();
}

class _FocusTencentDiaogState extends State<FocusTencentDiaog>
    with SingleTickerProviderStateMixin {
  double _scale;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 100),
      lowerBound: 0.0,
      upperBound: 0.1,
    )..addListener(() {
        setState(() {});
      });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    _scale = 1 - _controller.value;
    return _initBody();
  }

  Widget _initBody() {
    return Center(
        child: Container(
      // color: ThemeColors.colorTheme,
      width: ScreenAdapter.width(730),
      child: Column(mainAxisSize: MainAxisSize.min, children: [
        Container(
          height: ScreenAdapter.height(780),
          width: double.infinity,
          decoration: BoxDecoration(
            // color: ThemeColors.colorType6,
            image: DecorationImage(
                image:
                    ExactAssetImage(RPath.imgPath + "img_focus_tencent_bg.png"),
                fit: BoxFit.fitWidth),
          ),
          child: Stack(
            alignment: Alignment.center,
            children: [
              Column(children: [
                SizedBox(height: ScreenAdapter.height(260)),
                Text("立享9.9元包月特价套餐",
                    style: TextStyle(
                        color: ThemeColors.colorType52,
                        fontSize: ScreenAdapter.sp(36),
                        fontWeight: FontWeight.bold)),
                SizedBox(height: ScreenAdapter.height(10)),
                GestureDetector(
                    onLongPress: () async {
                      ByteData bytes = await rootBundle.load(
                        RPath.imgPath + "img_qn_gzh.png",
                      );
                      saveImage(bytes.buffer.asUint8List());
                    },
                    child: Image.asset(
                      RPath.imgPath + "img_qn_gzh.png",
                      width: ScreenAdapter.width(220),
                      height: ScreenAdapter.width(220),
                      fit: BoxFit.cover,
                    )),
                Text("长按保存",
                    style: TextStyle(
                        color: ThemeColors.colorType1,
                        fontSize: ScreenAdapter.sp(20),
                        fontWeight: FontWeight.w600)),
                SizedBox(height: ScreenAdapter.height(30)),
                GestureDetector(
                  onTapDown: (details) {
                    _controller.forward();
                  },
                  onTapUp: (details) {
                    _controller.reverse();
                    launch("weixin://");
                    LRouter.navigatorCtx(context).pop();
                  },
                  child: Transform.scale(
                    scale: _scale,
                    child: Container(
                      child: Image.asset(
                          RPath.imgPath + "img_btn_focus_tencent.png",
                          width: ScreenAdapter.width(476),
                          height: ScreenAdapter.height(142)),
                    ),
                  ),
                )
              ]),
            ],
          ),
        ),
        Align(
          alignment: Alignment.center,
          child: IconButton(
              onPressed: () {
                LRouter.navigatorCtx(context).pop(context);
              },
              icon: Image.asset(RPath.imgPath + "icon_dialog_close.png",
                  fit: BoxFit.contain,
                  width: ScreenAdapter.width(60),
                  height: ScreenAdapter.width(60))),
        ),
      ]),
    ));
  }
}
